package com.mm.cloud.common.core.util;

import org.apache.commons.lang3.RandomStringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 短信工具
 *
 * @author mr
 * @since 2021-09-15
 */
public class SmsUtils {

    /**
     * 获取随机6位数验证码
     *
     * @return
     */
    public static String genLoginCode() {
        return RandomStringUtils.random(6, "0123456789");
    }


    /**
     * 校验手机号是否合法
     *
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        if (phone.length() != 11) {
            return false;
        } else {
            String regex = "^[1][0,1,2,3,4,5,6,7,8,9][0-9]{9}$";
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(phone);
            return m.matches();
        }
    }
}
